package com.longcai.piaojia.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/9/6.
 */
@HttpInlet(Conn.SEARCH_GET)
public class SearchResultGet extends BaseAsyGet<SearchResultGet.SearchResultListEntity> {

    public String title;
    public int page;

    public SearchResultGet(AsyCallBack<SearchResultListEntity> asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected SearchResultListEntity parser(JSONObject object) throws Exception {

        if(object.optInt("code")==200){

            SearchResultListEntity searchResultListEntity = new SearchResultListEntity();

            searchResultListEntity.total = object.optInt("total");
            searchResultListEntity.current_page = object.optInt("current_page");

            JSONArray jsonArray = object.optJSONArray("data");
            for(int i=0;i<jsonArray.length();i++){

                JSONObject jsonObject = jsonArray.optJSONObject(i);

                SearchResultEntity searchResultEntity = new SearchResultEntity();
                searchResultEntity.id = jsonObject.optString("id");
                searchResultEntity.title = jsonObject.optString("title");
                searchResultEntity.picurl = Conn.IMAGE_BANNER_URL + jsonObject.optString("picurl");
                searchResultEntity.start_time = jsonObject.optString("start_time");
                searchResultEntity.placeid = jsonObject.optString("placeid");
                searchResultEntity.is_seat = jsonObject.optString("is_seat");
                searchResultEntity.price_low = jsonObject.optString("price_low");
                searchResultEntity.price_high = jsonObject.optString("price_high");
                searchResultEntity.status = jsonObject.optString("status");
                searchResultEntity.place_name = jsonObject.optString("place_name");

                searchResultListEntity.data.add(searchResultEntity);

            }

            return searchResultListEntity;

        }

        TOAST = object.optString("message");

        return null;
    }

    public static class SearchResultListEntity{

        public List<SearchResultEntity> data = new ArrayList<>();

        public int total, current_page;

    }

    public static class SearchResultEntity{

        public String id, title, picurl, start_time, placeid, is_seat, price_low, price_high, status, place_name;

    }

}
